package com.admin.library.service.impl;

import com.admin.library.domain.entity.BookClass;
import com.admin.library.domain.entity.Publisher;
import com.admin.library.mapper.BookClassMapper;
import com.admin.library.service.BookClassService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Lii
 * @create 2022-05-27 20:43
 */

@Service("bookClassService")
public class BookClassServiceImpl extends ServiceImpl<BookClassMapper,BookClass>implements BookClassService{

    @Resource
    private BookClassService bookClassService;


    @Override
    public Map<String, Object> page(Page<BookClass> page, BookClass bookClasser) {
        Integer id = bookClasser.getId();
        String bookClass = bookClasser.getBookClass();
        String bookClassmore = bookClasser.getBookClassmore();

        QueryWrapper<BookClass> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(!StringUtils.isEmpty(id), BookClass::getId, id)
                .like(!StringUtils.isEmpty(bookClass), BookClass::getBookClass, bookClass)
                .like(!StringUtils.isEmpty(bookClassmore), BookClass::getBookClassmore, bookClassmore);


        Page<BookClass> selectPage = this.baseMapper.selectPage(page, wrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("list", selectPage.getRecords());
        map.put("total", selectPage.getTotal());
        return map;
    }
}
